package com.sgb.kjwl.view.ui.activity.pick;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;

import androidx.databinding.DataBindingUtil;

import com.apeng.permissions.EsayPermissions;
import com.apeng.permissions.OnPermission;
import com.chuanglan.shanyan_sdk.OneKeyLoginManager;
import com.chuanglan.shanyan_sdk.listener.OneKeyLoginListener;
import com.chuanglan.shanyan_sdk.listener.OpenLoginAuthListener;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.entity.LocalMedia;
import com.sgb.alimaplibrary.MapLocationTools;
import com.sgb.alimaplibrary.util.ToastUtil;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.api.GsonManager;
import com.sgb.kjwl.databinding.ActivityEnterpriseBidding5Binding;
import com.sgb.kjwl.di.pick.DaggerPickComponent;
import com.sgb.kjwl.di.pick.PickModule;
import com.sgb.kjwl.model.entity.LoginEntity;
import com.sgb.kjwl.model.entity.UserMsgEntity;
import com.sgb.kjwl.model.entity.pick.EnterpriseBiddingDetailEntity5;
import com.sgb.kjwl.model.entity.pick.EnterpriseBiddingJoinEntity5;
import com.sgb.kjwl.model.entity.pick.PhtotEntity3;
import com.sgb.kjwl.model.entity.transport.MapLongAndLatEntity;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.sgb.kjwl.model.entity.user.OneKeyLoginEntity;
import com.sgb.kjwl.utils.ConfigUtils;
import com.swgk.core.event.EventConstant;
import com.sgb.kjwl.view.event.LoginEvent;
import com.sgb.alimaplibrary.SelectAddressActivity;
import com.sgb.kjwl.view.ui.activity.manage.WebsiteInfoActivity;
import com.sgb.kjwl.view.ui.activity.self.publish.GetPositionActivity;
import com.sgb.kjwl.view.ui.activity.self.userInfo.VerificationCodeLoginActivity;
import com.swgk.core.base.aroute.ARouterStartWebBase;
import com.swgk.core.mmkvutil.CacheMarker;
import com.swgk.core.dialog.RoundCornerDialog;
import com.sgb.kjwl.viewmodel.pick.EnterpriseBiddingModel5;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.mmkvutil.MkvUtils;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;

import org.greenrobot.eventbus.EventBus;

import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import javax.inject.Inject;

/**
 * Description: 报名报价
 * - - - - - - - - - - - - - - - - - - -
 * Created by zhangchi on 2020/9/10.
 * - - - - - - - - - - - - - - - - - - -
 * Version 2.7版本创建
 */
public class EnterpriseBiddingActivity5 extends AppActivity {

    private ActivityEnterpriseBidding5Binding binding;
    //正常（zc），申请（sq）
    private String categoryModel;
    private String no;
    //招标方式：1、资格预审；2、资格后审；3、报价即报名
    private int verticalTypeValue;
    private int state;
    //1.报名2.投标3.报名申请/投标申请4.竞价
    private int type = 0;
    private EnterpriseBiddingDetailEntity5 detailData;
    private int step = 0;  //当前进度
    private String titleName = ""; //标题
    private List<String> urls = new ArrayList<>();
    private List<File> fileList = new ArrayList<>();
    List<PhtotEntity3> phtotEntity3List = new ArrayList<>();

    EnterpriseBiddingJoinEntity5 enterpriseBiddingJoinEntity5 = new EnterpriseBiddingJoinEntity5();

    private String[] titles;

    @Inject
    EnterpriseBiddingModel5 model5;
    private String lat;
    private String lng;
    private boolean haveQuotationList = false;
    private MapLocationTools mapLocationTools;
    private String url;

    public static void start(Context context, String categoryModel, String no, Integer verticalTypeValue, int state,String lat,String lng) {
        Intent intent = new Intent();
        intent.setClass(context, EnterpriseBiddingActivity5.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.putExtra("category_model", categoryModel);
        intent.putExtra("NO", no);
        intent.putExtra("verticalTypeValue", verticalTypeValue);
        intent.putExtra("state", state);
        intent.putExtra("lat", lat);
        intent.putExtra("lng", lng);
        context.startActivity(intent);
    }

    public static void start(Context context, String categoryModel, String no, Integer verticalTypeValue, int state,String lat,String lng,String url) {
        Intent intent = new Intent();
        intent.setClass(context, EnterpriseBiddingActivity5.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.putExtra("category_model", categoryModel);
        intent.putExtra("NO", no);
        intent.putExtra("verticalTypeValue", verticalTypeValue);
        intent.putExtra("state", state);
        intent.putExtra("lat", lat);
        intent.putExtra("lng", lng);
        intent.putExtra("url", url);
        context.startActivity(intent);
    }

    @Override
    protected boolean statusBarDark() {
        return false;
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerPickComponent.builder()
                .appComponent(appComponent)
                .pickModule(new PickModule(this))
                .build()
                .inject(this);
    }

    @Override
    protected void init() {
        model5.findTenderApply(no, type);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(EnterpriseBiddingActivity5.this, R.layout.activity_enterprise_bidding5);
        binding.topLayout.ivBack.setOnClickListener(this);
        binding.tvCommit.setOnClickListener(this);
        binding.tvPrevious.setOnClickListener(this);
        binding.tvNext.setOnClickListener(this);

        categoryModel = getIntent().getStringExtra("category_model");
        no = getIntent().getStringExtra("NO");
        verticalTypeValue = getIntent().getIntExtra("verticalTypeValue", 0);
        state = getIntent().getIntExtra("state", 0);
        lat = getIntent().getStringExtra("lat");
        lng = getIntent().getStringExtra("lng");
        url = getIntent().getStringExtra("url");

        if (state == 9 && verticalTypeValue != 3) { // 9  我要报名         verticalTypeValue  == 3 我要报名/报价
            type = 1;  //1.报名2.投标3.报名申请/投标申请4.竞价
        } else if (state == -100 && verticalTypeValue == 0) {  //去竞价传过来的
            type = 4;  //1.报名2.投标3.报名申请/投标申请4.竞价
        } else if (state == 2 || state == 6 || verticalTypeValue == 3) {    //2、招标中、6、再次招标
            type = 2;  //1.报名2.投标3.报名申请/投标申请4.竞价
        }

        if ("sq".equals(categoryModel)) {   //只有申请报名的接口
            if (verticalTypeValue == 3) {
                type = 2;
            } else {
                type = 1;
            }
        }

        if("jingjia".equals(categoryModel)){
            binding.companyTitle.setText("采购企业");
        }

        //投标/报价人信息
        initBidderInformationAdapter();
    }

    //投标/报价人信息 初始化布局
    private void initBidderInformationAdapter() {
        binding.layoutBidderInformation.setinitView(type,model5,verticalTypeValue);
    }

    /**
     * 初始化拉取到的数据
     *
     * @param data
     */
    public void setDetailData(EnterpriseBiddingDetailEntity5 data) {
        detailData = data;
        if(data == null){
            return;
        }
        int listType = data.getType();
        binding.setViewModel(model5);
        String sq = "";
        if (categoryModel.equals("sq")) {
            sq = "申请";
        } else {
            sq = "";
        }

        boolean b = listType == 6 || listType == 7 || listType == 8 || listType == 9 || listType == 10 || listType == 13 || listType == 20;

        if (type == 1) {
            titleName = sq + "报名";
            titles = new String[]{"投标人要求响应", "投标人信息"};
            binding.publishViewName.setText("招标名称");
        } else if (type == 4) {
            titleName = "竞价";
            //无清单类，投标包括：（招标类型包括：“勘察设计 6”、“建筑设计7”、“8工程监理”、“9工程造价咨询”、“10工程总承包”时
            if (b) {
                titles = new String[]{"竞价要求响应", "报价人信息"};
            } else {
                titles = new String[]{"竞价要求响应", "竞价清单报价", "报价人信息"};
            }
            binding.publishViewName.setText("采购标题");
        } else {
            titleName = sq + "投标";
            if (verticalTypeValue == 3) {
                titleName = sq + "报名&报价";
            }
            //无清单类，投标包括：（招标类型包括：“勘察设计 6”、“建筑设计7”、“8工程监理”、“9工程造价咨询”、“10工程总承包”时
            if (b) {
                titles = new String[]{"招标要求响应", "投标人信息"};
            } else {
                titles = new String[]{"招标要求响应", "招标清单报价", "投标人信息"};
            }

            binding.publishViewName.setText("招标名称");
        }

        binding.publishView.setText(data.getName());
        binding.companyName.setText(data.getTenderBidPeople());
        binding.topLayout.titleView.setText(data.getName() + "-" + titleName);
        EnterpriseBiddingDetailEntity5.ZcTenderingApplyDTOEntity zcTenderingApplyDTOEntity = data.getZcTenderingApplyDTO();
        binding.tvCompany.setText(data.getComName());
        binding.tvCompany.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(data.getComNo() != 0){
                    if (TextUtils.isEmpty(String.valueOf(data.getComNo()))) {
                        ToastUtil.show(getActivity(), "企业店铺no不能为空");
                        return;
                    }
                    WebsiteInfoActivity.start(getActivity(), String.valueOf(data.getComNo()), WebsiteInfoActivity.WEBSITE_FOR_COMPANY);
                }
            }
        });
        binding.imgService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if ("".equals(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                    jumpLogin();
                } else {
                    // 跳转H5聊天
                    if (!TextUtils.isEmpty(data.getCustomerServiceContactsId())) {
                        model5.findCustomerServiceImAccount(data.getCustomerServiceContactsId());
                    } else {
                        checkAllowDialog("招标方未设置客服人员，不支持交流。");
                    }
                }
            }
        });
        if (!TextUtils.isEmpty(data.getRegionSAddress())) {
            binding.addressLine.setVisibility(View.VISIBLE);
            if (listType == 12 || listType == 11) {
                binding.addressTitle.setText("使用地址");
            } else if (listType == 3) {
                binding.addressTitle.setText("收货地址");
            } else if (listType == 5 || listType == 1) {
                binding.addressTitle.setText("工作地址");
            } else if (listType == 14) {
                binding.addressTitle.setText("土地地址");
            } else if (listType == 15 || listType == 16 || listType == 17 || listType == 18 || type == 20) {
                binding.addressTitle.setText("所在地址");
            } else if (listType == 19) {
                binding.addressTitle.setText("发货地址");
            }  else {
                binding.addressTitle.setText("项目地址");
            }
            binding.addressContent.setText(data.getRegionSAddress());
            binding.locationMap.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    PickCompanyLocationMapActivity.start(EnterpriseBiddingActivity5.this, lat,lng,
                            data.getRegionSAddress(), data.getComName());
                }
            });
            if (!TextUtils.isEmpty(data.getDistance())) {
                binding.tvDistance.setVisibility(View.VISIBLE);
                binding.tvDistance.setText(data.getDistance() + "km");
                binding.tvDistance.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        GetPositionActivity.start(getActivity(), Double.valueOf(lng), Double.valueOf(lat), data.getRegionSAddress());
                    }
                });
            } else {
                binding.tvDistance.setVisibility(View.GONE);
            }
        } else {
            binding.addressLine.setVisibility(View.GONE);
        }


        int size = 10;
        if (categoryModel.equals("sq")){
            size = 8;
        }
        if (!TextUtils.isEmpty(data.getName()) && data.getName().length() >= size) {
            binding.topLayout.titleView.setText(data.getName().substring(0, size) + "...-" + titleName);
        }
        model5.applicationQuotationEntity.get().setTenderNo(no);

        //设置进度标题
        binding.enterpriseStepView.setTitles(titles);
        //设置进度园大小
        binding.enterpriseStepView.setCircleRadius(15);
        //设置当前进度不显示数字
        binding.enterpriseStepView.setCircleSelectTestNum(false);

        initRobot(); //响应回显
        initBiddingQuotation(); //清单数据回显
        initBidderInformation(); //用户信息回显

        setButtonView();
    }

    /**
     * 报名用户数据回显
     */
    private void initBidderInformation() {
        binding.layoutBidderInformation.initBidderInformation(detailData,enterpriseBiddingJoinEntity5);
    }

    /**
     * 清单数据回显
     */
    private void initBiddingQuotation() {
        if (detailData != null) {
            if (detailData.getGoods() != null && detailData.getGoods().size() > 0) {
                if(TextUtils.isEmpty(detailData.getGoods().get(0).getPrice())){
                    haveQuotationList = false;
                }else{
                    haveQuotationList = true;
                }
            }
            binding.biddingListQuotationLayout.setData(detailData, categoryModel);
        }
    }

    /**
     * 响应数据回显
     */
    private void initRobot() {
        if (detailData != null && detailData.getTenderingAsks() != null) {
            binding.tenderRequestResponseView.setNewData(detailData.getTenderingAsks());
        }
    }

    /**
     * 报名竞价投标成功接口调用成功跳转
     */
    public void addSucc() {

        MToast.showLongToast1(this, "您的" + titleName + "已经提交成功，请留意后期通知", Gravity.CENTER);
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
                           public void run() {
                               finish();
                               if(type == 4){
                                   ARouterStartWebBase.start(getActivity(),url);
                               }
                           }
                       },
                3*1000);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == PictureConfig.CHOOSE_REQUEST) {// 图片结果回调
                List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data);
                setIMage(selectList);
            } else if (requestCode == 255) {
                if (data == null) {
                    return;
                }
                binding.layoutBidderInformation.setAddressText(data);
            }
        }
    }

    public void setIMage(List<LocalMedia> selectList) {
        fileList.clear();
        urls.clear();
        for (LocalMedia localMedia : selectList) {
            File file = new File(localMedia.getRealPath());
            fileList.add(file);
            urls.add(localMedia.getRealPath());
        }
        model5.uploadMutiFileModel(fileList.get(0), 0, 1);
    }

    public void uploadImgSuccess(String urls) {
        PhtotEntity3 phtotEntity3 = new PhtotEntity3("第一张图片",urls);
        phtotEntity3List.add(phtotEntity3);
        enterpriseBiddingJoinEntity5.setFiles(phtotEntity3List);
        if (step == 0) {
            //报名&报价
            binding.tenderRequestResponseView.setData(urls);
        } else {
            binding.layoutBidderInformation.uploadImgSuccess(urls);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.tv_previous:
                binding.nestedScrollView.smoothScrollTo(0, 0);
                step = binding.enterpriseStepView.getCurrentStep() - 1;
                //设置进度
                binding.enterpriseStepView.setCurrentStep(Math.max((step) % binding.enterpriseStepView.getStepNum(), 0));
                setButtonView();
                break;
            case R.id.tv_next:
                binding.nestedScrollView.smoothScrollTo(0, 0);
                if (step == 0) {
                    //当响应数据不为空，并且全部响应后才能继续，否则中断
                    if (!binding.tenderRequestResponseView.isNext()) {
                        MToast.showLongToast1(this, "还有要求未响应，全部响应后才可进入下一步", Gravity.CENTER);
                        return;
                    }
                    step = binding.enterpriseStepView.getCurrentStep() + 1;
                    //设置进度
                    binding.enterpriseStepView.setCurrentStep(Math.max((step) % binding.enterpriseStepView.getStepNum(), 0));
                    if (enterpriseBiddingJoinEntity5 != null) {
                        enterpriseBiddingJoinEntity5.setZcTenderingAsks(detailData.getTenderingAsks());
                    }
                    setButtonView();
                }
                break;
            case R.id.tv_commit:
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (binding.tvCommit.getText().equals("提交")) {
                            setCommit();
                        } else {
                            if (detailData!=null && detailData.getGoods() != null && detailData.getGoods().size() != 0){
                                setNext();
                            }else{
                                step = binding.enterpriseStepView.getCurrentStep() + 1;
                                //设置进度
                                binding.enterpriseStepView.setCurrentStep(Math.max((step) % binding.enterpriseStepView.getStepNum(), 0));
                                setButtonView();
                                binding.nestedScrollView.smoothScrollTo(0, 0);
                            }
                        }
                    }
                });
                break;
        }
    }

    /**
     * 用户点击的是下一步的业务
     */
    private void setNext() {
        if (enterpriseBiddingJoinEntity5 != null) {
            BigDecimal sum = binding.biddingListQuotationLayout.subPice();
            if (!haveQuotationList) {
                binding.biddingListQuotationLayout.setViewRed();
            }
            if ("0.00".equals(sum.toPlainString())) {
//                  MToast.showLongToast(this, "请填写第" + (i + 1) + "项清单单价未填写报价，全部填写才可进入下一步”");
//                MToast.showLongToast1(getActivity(), "部分价格未填写", Gravity.CENTER);
                MToast.showLongToast1(getActivity(), "还有清单未填写报价，全部填写才可进入下一步", Gravity.CENTER);
                return;
            }
            enterpriseBiddingJoinEntity5.setDetails(binding.biddingListQuotationLayout.getPriceList());
            showDialog(sum);
        }
    }

    /**
     * 用户点击的是提交的业务
     */
    private void setCommit() {
        //校验用户是否将投标人信息填写完整，不完整是给出提示
        String message = binding.layoutBidderInformation.getData();
        if(!TextUtils.isEmpty(message)){
            MToast.showLongToast(getActivity(), message, Gravity.CENTER);
            return;
        }
        if (type == 2) { // 投标
            if (categoryModel.equals("sq")) { //申请投标
                enterpriseBiddingJoinEntity5.setTenderingId(no);
                model5.addTenderBidApply(enterpriseBiddingJoinEntity5);
            } else {
                if (verticalTypeValue == 3) {
                    enterpriseBiddingJoinEntity5.setTenderNo(no);
                    model5.saveApplyForEasy(enterpriseBiddingJoinEntity5);
                } else {
                    //后台让这么写   2022-01-29
                    enterpriseBiddingJoinEntity5.setTenderNo(no);
                    enterpriseBiddingJoinEntity5.setTender(no);
                    if(enterpriseBiddingJoinEntity5.getDetails() == null){
                        enterpriseBiddingJoinEntity5.setDetails(new ArrayList<>());
                    }
                    model5.saveCompanyBidding(enterpriseBiddingJoinEntity5);
                }
            }
        } else if (type == 1) { //报名
            if (enterpriseBiddingJoinEntity5 != null && enterpriseBiddingJoinEntity5.getDetails() != null) {
                enterpriseBiddingJoinEntity5.getDetails().clear();
            }
            enterpriseBiddingJoinEntity5.setTenderingId(no);
            if (categoryModel.equals("sq")) { //申请报名
                model5.addTenderBidApply(enterpriseBiddingJoinEntity5);
            } else {
                model5.saveApply(enterpriseBiddingJoinEntity5);
            }
        } else { // 竞价
            enterpriseBiddingJoinEntity5.setBidId(no);
            model5.publishBidding(enterpriseBiddingJoinEntity5);
        }
    }

    /**
     * 弹框提示用户清单报价总额
     * @param sum
     */
    private void showDialog(BigDecimal sum) {
        View view = View.inflate(getActivity(), R.layout.dialog_two_btn, null);
        final RoundCornerDialog roundCornerDialog = new RoundCornerDialog(getActivity(), 0, 0, view, R.style.RoundCornerDialog);
        roundCornerDialog.show();
        roundCornerDialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失

        TextView tv_message = view.findViewById(R.id.tv_message);
        TextView tv_title = view.findViewById(R.id.tv_title);
        TextView tv_logout_confirm = view.findViewById(R.id.tv_logout_confirm);
        TextView tv_logout_cancel = view.findViewById(R.id.tv_logout_cancel);
        tv_title.setText("确认操作");
        tv_title.setVisibility(View.VISIBLE);
        tv_message.setText("总报价合计" + sum.toPlainString() + "元");

        //确定
        tv_logout_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                step = binding.enterpriseStepView.getCurrentStep() + 1;
                //设置进度
                binding.enterpriseStepView.setCurrentStep(Math.max((step) % binding.enterpriseStepView.getStepNum(), 0));
                setButtonView();
                roundCornerDialog.dismiss();
                binding.nestedScrollView.smoothScrollTo(0, 0);
            }
        });
        //取消
        tv_logout_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                roundCornerDialog.dismiss();
            }
        });
    }

    /**
     * 更改底部控件
     */
    private void setButtonView() {
        if (step <= 0) {
            binding.llOneLayout.setVisibility(View.VISIBLE);
            binding.llTowLayout.setVisibility(View.GONE);

            binding.tvNext.setText("下一步");
            //控制 响应布局显示或隐藏
            binding.tenderRequestResponseView.setView();

            binding.biddingListQuotationLayout.setView(View.GONE);

            binding.layoutBidderInformation.setView(View.GONE);

        } else if (step == 1) {
            binding.llOneLayout.setVisibility(View.GONE);
            binding.llTowLayout.setVisibility(View.VISIBLE);
            //1.报名2.投标3.报名申请/投标申请4.竞价
            if (titles.length <= 2) {
                binding.tvPrevious.setText("上一步");
                binding.tvCommit.setText("提交");
                binding.tenderRequestResponseView.setView(View.GONE);
                binding.biddingListQuotationLayout.setView(View.GONE);
                binding.layoutBidderInformation.setView(View.VISIBLE);
            } else {
                binding.tvPrevious.setText("上一步");
                binding.tvCommit.setText("下一步");

                binding.tenderRequestResponseView.setView(View.GONE);

                binding.biddingListQuotationLayout.setView();
                binding.layoutBidderInformation.setView(View.GONE);
            }
        } else {
            binding.llOneLayout.setVisibility(View.GONE);
            binding.llTowLayout.setVisibility(View.VISIBLE);
            binding.tvCommit.setText("提交");
            binding.tenderRequestResponseView.setView(View.GONE);
            binding.biddingListQuotationLayout.setView(View.GONE);
            binding.layoutBidderInformation.setView(View.VISIBLE);
        }
    }

    //服务范围
    public void showAddressPop(List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> datas) {
        binding.layoutBidderInformation.showAddressPop(datas);
    }

    //  返回经纬度信息
    public void getLocationLL(MapLongAndLatEntity data) {
        if (!TextUtils.isEmpty(data.getLat())) {
            if (!TextUtils.isEmpty(data.getLng())) {
                Intent intent = new Intent();
                intent.setClass(this, SelectAddressActivity.class);
                intent.putExtra(SelectAddressActivity.TITLE, "详细地址");
                intent.putExtra(SelectAddressActivity.HINT, "请输入地址");
                intent.putExtra(SelectAddressActivity.SAVE_TEXT, "确定");
                intent.putExtra(SelectAddressActivity.LATITUDE, Double.parseDouble(data.getLat()));
                intent.putExtra(SelectAddressActivity.LONGTITUDE, Double.parseDouble(data.getLng()));
                startActivityForResult(intent, 255);
            }
        }
    }

    /**
     * 隐藏软键盘
     */
    private void setSoftWareHide() {
        InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) {
            imm.hideSoftInputFromWindow(this.getWindow().getDecorView().getWindowToken(), 0);
        }
    }

    public void jumpLogin() {
        boolean shanyan = MkvUtils.get().getBoolean(MkvUtils.CommomData, CacheMarker.ShanYan, false);
        if (shanyan) {
            //校验权限
            //申请动态权限
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                //6.0以上运行时权限处理
                EsayPermissions.with(EnterpriseBiddingActivity5.this).constantRequest().permission(PERMISSIONS).request(new OnPermission() {
                    @Override
                    public void hasPermission(List<String> granted, boolean isAll) {
                        openLoginPage();
                    }

                    @Override
                    public void noPermission(List<String> denied, boolean quick) {
                        openLoginPage();
                    }
                });

            } else {
                //有权限
                openLoginPage();
            }

        } else {
            VerificationCodeLoginActivity.start(EnterpriseBiddingActivity5.this, EventConstant.EVENT_TENDER_DETAILS_3_JUMP);
        }
    }

    //闪验
    static final String[] PERMISSIONS = new String[]{
            Manifest.permission.READ_PHONE_STATE
    };

    /**
     * 拉起授权页
     */
    private void openLoginPage() {
        //设置授权页样式
        OneKeyLoginManager.getInstance().setAuthThemeConfig(ConfigUtils.getCJSConfig(this));
        //开始拉取授权页
        DialogHelper.showProgressDialog(this, null, "数据加载中", 0, true, null).setCanceledOnTouchOutside(true);
        OneKeyLoginManager.getInstance().openLoginAuth(false, new OpenLoginAuthListener() {
            @Override
            public void getOpenLoginAuthStatus(int code, String result) {
                DialogHelper.dismissProgressDialog();
                if (code != 1000) {
                    VerificationCodeLoginActivity.start(EnterpriseBiddingActivity5.this, EventConstant.EVENT_TENDER_DETAILS_3_JUMP);
                }
            }
        }, new OneKeyLoginListener() {
            @Override
            public void getOneKeyLoginStatus(int code, String result) {
                DialogHelper.dismissProgressDialog();
                if (code == 1000) {
                    OneKeyLoginEntity oneKeyLoginEntity = GsonManager.getInstance().getGson().fromJson(result, OneKeyLoginEntity.class);
                    oneKeyLoginEntity.setPlateform("Android");
                    model5.oneKeyLogin(oneKeyLoginEntity);
                }
            }
        });
    }

    /**
     * 一键登录成功
     *
     * @param loginEntity
     * @param phoneNumber
     */
    public void loginSucceed(LoginEntity loginEntity, String phoneNumber) {
        LoginEvent loginEvent = new LoginEvent();
        loginEvent.setMessageData(phoneNumber);
        loginEvent.setMessageTag(EventConstant.EVENT_TENDER_DETAILS_3_JUMP);
        loginEvent.setObject(loginEntity);
        EventBus.getDefault().postSticky(loginEvent);
    }

    public void getUserMsgSucceed(UserMsgEntity userMsgEntity) {
        LoginEvent loginEvent = new LoginEvent();
        loginEvent.setMessageTag(EventConstant.EVENT_USER_MSG);
        loginEvent.setMessageData(userMsgEntity);
        EventBus.getDefault().postSticky(loginEvent);
    }

    public void checkAllowDialog(String msg) {
        View view = View.inflate(getActivity(), R.layout.dialog_two_btn, null);
        final RoundCornerDialog roundCornerDialog = new RoundCornerDialog(getActivity(), 0, 0, view, R.style.RoundCornerDialog);
        roundCornerDialog.show();
        roundCornerDialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失
        TextView tv_message = view.findViewById(R.id.tv_message);
        TextView tv_title = view.findViewById(R.id.tv_title);
        TextView tv_logout_confirm = view.findViewById(R.id.tv_logout_confirm);
        TextView tv_logout_cancel = view.findViewById(R.id.tv_logout_cancel);

        tv_logout_cancel.setVisibility(View.GONE);
        tv_title.setVisibility(View.VISIBLE);
        tv_title.setText("提示");

        tv_message.setText(msg);

        //确定
        tv_logout_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                roundCornerDialog.dismiss();
            }
        });
    }


    @Override
    public void onResume() {
        super.onResume();
        String localLng = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LONGITUDE_ID, "");
        String localLat = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LATITUDE_ID, "");
        if (localLng == "" && localLat == "") {
            getLoction();
        }
    }

    private void getLoction() {
        if (mapLocationTools == null){
            mapLocationTools = new MapLocationTools(getActivity());
        }
        mapLocationTools.initLocation(false);
        mapLocationTools.setLocationListener(new MapLocationTools.LocationListener() {
            @Override
            public void getLocationListener(String address, Double Longitude, Double Latitude) {
                SharedPreferenceUtil.getInstance().saveString(SharedPreferenceUtil.LONGITUDE_ID,String.valueOf(Longitude));
                SharedPreferenceUtil.getInstance().saveString(SharedPreferenceUtil.LATITUDE_ID,String.valueOf(Latitude));
            }
        });
        mapLocationTools.startLocation();
    }
}